const db = require('../../db');

//创建新时间轴信息
exports.addNewTimeRecord = (order_id,order_state,amount,callback) => {
    const q = "INSERT INTO module2_time_record set order_id = ? , order_state = ? , amount = ?;";
    const values =[order_id ,order_state,amount];

    db.query(q, values, (err, results) => {
        if (err) {
          callback(err);
        } else if (results.affectedRows !== 1) {
          callback(new Error("更新失败，请稍后再试！"));
        } else {
          callback(null, "更新成功！", 0);
        }
    });
}


//输入订单号，查询订单信息
exports.TimeRecordIdSearch = (req, res) => {
    const q = "Select * from module2_time_record WHERE order_id = ? order by cur_time desc;";
    const values = req.params.order_id;
    db.query(q, values,(err, results) => {
        if (err) return(err.message)
        res.send({
          status: 0,
          message: '数据返回成功！',
          data: results,
        })
    });
};